package cn.sdhuijin.vms.controller;

import javax.inject.Inject;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import cn.sdhuijin.vms.model.Organization;
import cn.sdhuijin.vms.model.User;
import cn.sdhuijin.vms.service.IOrganizationService;

@Controller
@RequestMapping("/organization")
public class OrganizationController {
	@Inject
	private IOrganizationService organizationService;

	@RequestMapping(value = "", method = RequestMethod.GET)
	public String show(Model model) {
		return "organization/show";
	}

	@RequestMapping(value = "list", method = RequestMethod.GET)
	public String list(Model model) {
		Organization org = null;
		Subject user = SecurityUtils.getSubject();
		if (user.hasRole("admin")) {
			org = organizationService.get(0L);
		} else {
			org = ((User) user.getPrincipal()).getOrganization();
		}
		model.addAttribute("org", org);
		return "organization/list";
	}
}
